<?php
class PHZ_VbotShare
{

    public static function __setData( $room_info , $db_connect ){
        //是否需要进行推送
        if( $room_info['vbot_gid'] == "" ){
            return true;
        }
        //组合推送数据
        $room_info['p1'] = urldecode( PHZ_Member::__getFieldBy_ID( $room_info['room_player_1'] , "name" , $db_connect ) );
        $room_info['p2'] = urldecode( PHZ_Member::__getFieldBy_ID( $room_info['room_player_2'] , "name" , $db_connect ) );
        $room_info['p3'] = urldecode( PHZ_Member::__getFieldBy_ID( $room_info['room_player_3'] , "name" , $db_connect ) );
        if( $room_info['player_1_score'] >= 0 ){$room_info['p1'] = $room_info['p1'] . " ：+" . $room_info['player_1_score'];}else{$room_info['p1'] = $room_info['p1'] . " ：" . $room_info['player_1_score'];}
        if( $room_info['player_2_score'] >= 0 ){$room_info['p2'] = $room_info['p2'] . " ：+" . $room_info['player_2_score'];}else{$room_info['p2'] = $room_info['p2'] . " ：" . $room_info['player_2_score'];}
        if( $room_info['player_3_score'] >= 0 ){$room_info['p3'] = $room_info['p3'] . " ：+" . $room_info['player_3_score'];}else{$room_info['p3'] = $room_info['p3'] . " ：" . $room_info['player_3_score'];}
        //组合推送数据（输或者赢）
        $room_info['p1_e'] = $room_info['player_1_score'] >= 0 ? 'win' : 'bad';
        $room_info['p2_e'] = $room_info['player_2_score'] >= 0 ? 'win' : 'bad';
        $room_info['p3_e'] = $room_info['player_3_score'] >= 0 ? 'win' : 'bad';
        //进行平分计算
        if( $room_info['player_1_score'] == 0 ){$room_info['p1_e'] = "ping";}
        if( $room_info['player_2_score'] == 0 ){$room_info['p2_e'] = "ping";}
        if( $room_info['player_3_score'] == 0 ){$room_info['p3_e'] = "ping";}
        //执行推送操作
        $url       = "http://106.14.223.50/development/share.php";
        $post_data = array (
            "name"    => "yangxiaohong",
            "room_id" => $room_info['room_id'],
            "gid"     => $room_info['vbot_gid'],
            "p1" => $room_info['p1'],"p1_e" => $room_info['p1_e'],
            "p2" => $room_info['p2'],"p2_e" => $room_info['p2_e'],
            "p3" => $room_info['p3'],"p3_e" => $room_info['p3_e'],
            "g_time" => date('Y-m-d H:i:s')
        );
        print_r( $post_data );
        $shareLog = self::__post( $url , $post_data );
        echo $shareLog;
    }

    public static function __post( $url , $post_data ){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output;
    }
}
?>